package com.teamide.bean;

import java.util.List;

/**
 * 分页结果集
 * 
 * @author ZhuLiang
 *
 * @param <T>
 *            单个数据类型
 */
public class PageResultBean<T> extends ResultBean<List<T>> {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	// 当前页
	private int pageindex = 1;

	// 总页数
	private int totalpages = 0;

	// 总记录数
	private int totalcount = 0;

	// 每页记录
	private int pagesize = 10;

	// 上一页
	private int uppage = 1;

	// 下一页
	private int nextpage = 1;

	public int getUppage() {

		return uppage;
	}

	public int getNextpage() {

		return nextpage;
	}

	public int getPageindex() {
		if (pageindex <= 0) {
			pageindex = 1;
		}
		return pageindex;
	}

	public void setPageindex(int pageindex) {

		this.pageindex = pageindex;

		nextpage = getPageindex() + 1;
		if (nextpage >= totalpages) {
			nextpage = totalpages;
		}

		uppage = getPageindex() - 1;
		if (uppage <= 1) {
			uppage = 1;
		}
	}

	public int getTotalpages() {

		return totalpages;
	}

	public void setTotalpages(int totalpages) {

		this.totalpages = totalpages;
	}

	public int getTotalcount() {

		return totalcount;
	}

	public void setTotalcount(int totalcount) {

		this.totalcount = totalcount;
		totalpages = 0;
		if (totalcount % getPagesize() == 0) {
			totalpages = totalcount / getPagesize();
		} else {
			totalpages = totalcount / getPagesize() + 1;
		}
	}

	public int getPagesize() {
		if (pagesize <= 0) {
			pagesize = 10;
		}

		return pagesize;
	}

	public void setPagesize(int pagesize) {

		this.pagesize = pagesize;
	}

	public void setUppage(int uppage) {

		this.uppage = uppage;
	}

	public void setNextpage(int nextpage) {

		this.nextpage = nextpage;
	}

	public static long getSerialversionuid() {

		return serialVersionUID;
	}
}
